﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SubSonic.Repository;


namespace Blog.Models.UserServices
{
    public class RoleService:IRoleService
    {
        DataDataContext db=new DataDataContext();
        public int AddRole(string name, string desc)
        {
            throw new System.NotImplementedException();
        }

        public List<Role> GetAll()
        {
            throw new System.NotImplementedException();
        }

        public Role GetById(int id)
        {
            throw new System.NotImplementedException();
        }

        public void Update(Role Role)
        {
            throw new System.NotImplementedException();
        }

        public void Delete(int id)
        {
            throw new System.NotImplementedException();
        }

        public void Add(Role Role)
        {
            throw new System.NotImplementedException();
        }

        public void AssignRole(int userId, List<int> roles)
        {
            throw new System.NotImplementedException();
        }

        public IList<Role> GetRoleByUserId(int userId)
        {
            IList<UserRole> xx = (from c in db.UserRoles
                                     where c.UserId==userId
                                     select c).ToList();

            List<int> idSets = xx.Select(ur => ur.RoleId).ToList();

            IList<Role> roles = db.Roles.ToList();

            return roles.Where(r => idSets.Contains(r.RoleId)).ToList();
           
        }

        public bool HasRole(int userId, string roleName)
        {
            throw new System.NotImplementedException();
        }
    }
}
